function Food (el) {
    this.el = el     //保存地图对象
    this.k = 20
    this.h = 20
    this.food = null
    this.foodx = 0
    this.foody = 0

}



Food.prototype.create = function () {
    // 1创建div标签对象
    let divObj =document.createElement('div')
    // 2设置样式
    divObj.style.width = this.k + 'px'
    divObj.style.height = this.h + 'px'
    divObj.style.background = 'pink'
    divObj.style.position = 'absolute'

    // 3单独保证下食物的对象\
    this.food = divObj


    // 4在页面展示
    this.el.appendChild(divObj)
    // 5默认移动食物
    this.move()
}

Food.prototype.move = function () {
   let foodXMax = this.el.clientWidth / this.k -1
   let foodYMax = this.el.clientHeight / this.k -1

    this.foodx = Math.floor(Math.random()*(foodXMax-0+1)-0)*this.k
    this.foody = Math.floor(Math.random()*(foodYMax-0+1)-0)*this.k

    this.food.style.left= this.foodx + 'px'
    this.food.style.top = this.foody + 'px'
}